package com.yunhai.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yunhai.common.dto.GlobalException;
import com.yunhai.common.dto.PaginationVo;
import com.yunhai.common.utils.ObjectUtil;
import com.yunhai.common.utils.ReflectionCopy;
import com.yunhai.device.mapper.DmsPullTeaMototimeMapper;
import com.yunhai.device.service.DmsPullTeaMototimeService;
import com.yunhai.model.entity.dms.DmsPullTeaMototimeEntity;
import com.yunhai.model.vo.dms.DmsPullTeaMototimeQuery;
import com.yunhai.model.vo.dms.DmsPullTeaMototimeVo;
import org.apache.commons.beanutils.PropertyUtils;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DmsPullTeaMototimeServiceImpl implements DmsPullTeaMototimeService {

    @Resource
    private DmsPullTeaMototimeMapper dmsPullTeaMototimeMapper;

    /**
     * 获取 DmsPullTeaMototime 分页列表
     */
    @Transactional
    public IPage getDmsPullTeaMototimePagination(PaginationVo paginationVo, DmsPullTeaMototimeQuery dmsPullTeaMototimeQuery ) throws Exception {

        IPage page = new Page( paginationVo.getPageIndex(), paginationVo.getPageSize() );
        LambdaQueryWrapper<DmsPullTeaMototimeEntity> lqs = new LambdaQueryWrapper();
        dmsPullTeaMototimeMapper.selectPage(page, lqs);

        List<DmsPullTeaMototimeEntity> record = page.getRecords();
        if( !ObjectUtil.isNotEmptyList(record)){
            return page;
        }
        return null;
    }


    /**
     * 获取 DmsPullTeaMototime 所有数据
     *
    */
    @Transactional
    public List<DmsPullTeaMototimeEntity> getDmsPullTeaMototimeAllList( DmsPullTeaMototimeQuery dmsPullTeaMototimeQuery ) throws Exception {

        LambdaQueryWrapper<DmsPullTeaMototimeEntity> lqs = new LambdaQueryWrapper();
        List<DmsPullTeaMototimeEntity> list = dmsPullTeaMototimeMapper.selectList(lqs);
        return list;
    }


    /**
     * 获取 DmsPullTeaMototime 详情
    */
    @Transactional
    public DmsPullTeaMototimeEntity getDmsPullTeaMototimeDetail( Long id) throws Exception {

        DmsPullTeaMototimeEntity dmsPullTeaMototime = dmsPullTeaMototimeMapper.selectById(id);
        return dmsPullTeaMototime;
    }


    /**
     * 新增 DmsPullTeaMototime
     * */
    @Transactional
    public void addDmsPullTeaMototime(DmsPullTeaMototimeVo dmsPullTeaMototimeVo) throws Exception {

        DmsPullTeaMototimeEntity dmsPullTeaMototime = new DmsPullTeaMototimeEntity();
        ReflectionCopy.copyProperties( dmsPullTeaMototime, dmsPullTeaMototimeVo );
        dmsPullTeaMototimeMapper.insert(dmsPullTeaMototime);
        return;
    }


    /**
     * 更新 DmsPullTeaMototime
     * */
    @Transactional
    public void updateDmsPullTeaMototime( DmsPullTeaMototimeVo dmsPullTeaMototimeVo) throws Exception {

        if( dmsPullTeaMototimeVo.getId() == null ){
            throw GlobalException.gen(10021, "id不存在");
        }
        DmsPullTeaMototimeEntity dmsPullTeaMototime = new DmsPullTeaMototimeEntity();
        ReflectionCopy.copyProperties( dmsPullTeaMototime, dmsPullTeaMototimeVo );
        dmsPullTeaMototimeMapper.updateById(dmsPullTeaMototime);
        return;
    }

    /**
     * 删除 DmsPullTeaMototime
     * */
    @Transactional
    public void batchRemoveDmsPullTeaMototime( List<Long> ids ) throws Exception {


        if( !ObjectUtil.isNotEmptyList(ids) ){
            throw GlobalException.gen(10011, "要删除的id不存在");
        }
        dmsPullTeaMototimeMapper.deleteBatchIds(ids);
    }

}

      